package com.ruoyi.wapp.config.interceptor;

import com.ruoyi.common.constant.ResultConstants;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.wapp.util.MyConstants;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
		String method = request.getMethod();
		if(!"OPTIONS".equalsIgnoreCase(method)) {
			Object user = request.getAttribute(MyConstants.CONFIG.RUQUEST_MEMBER_NAME);
			if(user == null) {
				throw new BusinessException(ResultConstants.EX9112,MessageUtils.message("user.notfound"));
			}
		}
		return true;
	}

	
}
